﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Data;
using Kotonoha.Server.Extensions;

namespace Kotonoha.Server.UI.Converters {
    class Aggregator : IValueConverter {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
            // Check for design mode. 
            if ((bool)(DesignerProperties.IsInDesignModeProperty.GetMetadata(typeof(DependencyObject)).DefaultValue)) {
                return false;
            }

            if (value is string) {
                return value;
            }

            IList<string> strings = (IList<string>) value;
            if (strings.IsEmpty()) {
                return "";
            }
            return strings.Aggregate((s1, s2) => s1 + ", " + s2);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
            throw new System.NotImplementedException();
        }
    }
}
